import { Injectable } from '@nestjs/common';

export type User = {
  userId: number;
  username: string;
  password: string;
};
@Injectable()
export class UsersService {
  private readonly users = [
    {
      userId: 1,
      username: 'john',
      password: 'changeme',
    },
    {
      userId: 2,
      username: 'test',
      password: '1234',
    },
  ];

  findOne(username: string): Promise<User | undefined> {
    return new Promise((resolve, reject) => {
      const user = this.users.find((user) => user.username === username);
      if (user) {
        resolve(user);
      } else {
        reject(new Error('User not found'));
      }
    });
  }
}
